﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TinyGet.Models;

namespace TinyGet.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        TinyGetRepository repo = new TinyGetRepository();

        public ActionResult Index()
        {
            return View();
        }


        public ActionResult Create(String url)
        {
            String hash = repo.addLink(url);
            ViewData["LinkHash"] = hash;
            return View("Create");
        }

        public ActionResult GetLink(String hash)
        {
           TinyLink link = repo.getLink(hash);
            if (String.IsNullOrEmpty(link.Hash))
            {
                ViewData["hash"] = hash;
                return View("NotFound");
            }
            else
            {
                return View("Link", link);
            }
        }
    }
}
